/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.mto.module.karaoke.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.util.PortalUtil;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.mto.module.karaoke.model.UserSongs;
import com.mto.module.karaoke.model.UserSongsModel;
import com.mto.module.karaoke.model.UserSongsSoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the UserSongs service. Represents a row in the &quot;karaoke_UserSongs&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.mto.module.karaoke.model.UserSongsModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link UserSongsImpl}.
 * </p>
 *
 * @author vuonglm
 * @see UserSongsImpl
 * @see com.mto.module.karaoke.model.UserSongs
 * @see com.mto.module.karaoke.model.UserSongsModel
 * @generated
 */
@JSON(strict = true)
public class UserSongsModelImpl extends BaseModelImpl<UserSongs>
	implements UserSongsModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a user songs model instance should use the {@link com.mto.module.karaoke.model.UserSongs} interface instead.
	 */
	public static final String TABLE_NAME = "karaoke_UserSongs";
	public static final Object[][] TABLE_COLUMNS = {
			{ "userSongId", Types.BIGINT },
			{ "userId", Types.BIGINT },
			{ "commentNumber", Types.INTEGER },
			{ "listenNumber", Types.INTEGER },
			{ "mark", Types.INTEGER },
			{ "recodingUrl", Types.VARCHAR },
			{ "description", Types.VARCHAR },
			{ "isShow", Types.BOOLEAN },
			{ "avatar", Types.VARCHAR },
			{ "createDate", Types.TIMESTAMP },
			{ "songId", Types.BIGINT }
		};
	public static final String TABLE_SQL_CREATE = "create table karaoke_UserSongs (userSongId LONG not null primary key,userId LONG,commentNumber INTEGER,listenNumber INTEGER,mark INTEGER,recodingUrl STRING null,description VARCHAR(75) null,isShow BOOLEAN,avatar VARCHAR(75) null,createDate DATE null,songId LONG)";
	public static final String TABLE_SQL_DROP = "drop table karaoke_UserSongs";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.mto.module.karaoke.model.UserSongs"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.mto.module.karaoke.model.UserSongs"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.mto.module.karaoke.model.UserSongs"),
			true);
	public static long SONGID_COLUMN_BITMASK = 1L;
	public static long USERID_COLUMN_BITMASK = 2L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static UserSongs toModel(UserSongsSoap soapModel) {
		if (soapModel == null) {
			return null;
		}

		UserSongs model = new UserSongsImpl();

		model.setUserSongId(soapModel.getUserSongId());
		model.setUserId(soapModel.getUserId());
		model.setCommentNumber(soapModel.getCommentNumber());
		model.setListenNumber(soapModel.getListenNumber());
		model.setMark(soapModel.getMark());
		model.setRecodingUrl(soapModel.getRecodingUrl());
		model.setDescription(soapModel.getDescription());
		model.setIsShow(soapModel.getIsShow());
		model.setAvatar(soapModel.getAvatar());
		model.setCreateDate(soapModel.getCreateDate());
		model.setSongId(soapModel.getSongId());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<UserSongs> toModels(UserSongsSoap[] soapModels) {
		if (soapModels == null) {
			return null;
		}

		List<UserSongs> models = new ArrayList<UserSongs>(soapModels.length);

		for (UserSongsSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.mto.module.karaoke.model.UserSongs"));

	public UserSongsModelImpl() {
	}

	public long getPrimaryKey() {
		return _userSongId;
	}

	public void setPrimaryKey(long primaryKey) {
		setUserSongId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_userSongId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return UserSongs.class;
	}

	public String getModelClassName() {
		return UserSongs.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("userSongId", getUserSongId());
		attributes.put("userId", getUserId());
		attributes.put("commentNumber", getCommentNumber());
		attributes.put("listenNumber", getListenNumber());
		attributes.put("mark", getMark());
		attributes.put("recodingUrl", getRecodingUrl());
		attributes.put("description", getDescription());
		attributes.put("isShow", getIsShow());
		attributes.put("avatar", getAvatar());
		attributes.put("createDate", getCreateDate());
		attributes.put("songId", getSongId());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long userSongId = (Long)attributes.get("userSongId");

		if (userSongId != null) {
			setUserSongId(userSongId);
		}

		Long userId = (Long)attributes.get("userId");

		if (userId != null) {
			setUserId(userId);
		}

		Integer commentNumber = (Integer)attributes.get("commentNumber");

		if (commentNumber != null) {
			setCommentNumber(commentNumber);
		}

		Integer listenNumber = (Integer)attributes.get("listenNumber");

		if (listenNumber != null) {
			setListenNumber(listenNumber);
		}

		Integer mark = (Integer)attributes.get("mark");

		if (mark != null) {
			setMark(mark);
		}

		String recodingUrl = (String)attributes.get("recodingUrl");

		if (recodingUrl != null) {
			setRecodingUrl(recodingUrl);
		}

		String description = (String)attributes.get("description");

		if (description != null) {
			setDescription(description);
		}

		Boolean isShow = (Boolean)attributes.get("isShow");

		if (isShow != null) {
			setIsShow(isShow);
		}

		String avatar = (String)attributes.get("avatar");

		if (avatar != null) {
			setAvatar(avatar);
		}

		Date createDate = (Date)attributes.get("createDate");

		if (createDate != null) {
			setCreateDate(createDate);
		}

		Long songId = (Long)attributes.get("songId");

		if (songId != null) {
			setSongId(songId);
		}
	}

	@JSON
	public long getUserSongId() {
		return _userSongId;
	}

	public void setUserSongId(long userSongId) {
		_userSongId = userSongId;
	}

	@JSON
	public long getUserId() {
		return _userId;
	}

	public void setUserId(long userId) {
		_columnBitmask |= USERID_COLUMN_BITMASK;

		if (!_setOriginalUserId) {
			_setOriginalUserId = true;

			_originalUserId = _userId;
		}

		_userId = userId;
	}

	public String getUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
	}

	public void setUserUuid(String userUuid) {
		_userUuid = userUuid;
	}

	public long getOriginalUserId() {
		return _originalUserId;
	}

	@JSON
	public int getCommentNumber() {
		return _commentNumber;
	}

	public void setCommentNumber(int commentNumber) {
		_commentNumber = commentNumber;
	}

	@JSON
	public int getListenNumber() {
		return _listenNumber;
	}

	public void setListenNumber(int listenNumber) {
		_listenNumber = listenNumber;
	}

	@JSON
	public int getMark() {
		return _mark;
	}

	public void setMark(int mark) {
		_mark = mark;
	}

	@JSON
	public String getRecodingUrl() {
		if (_recodingUrl == null) {
			return StringPool.BLANK;
		}
		else {
			return _recodingUrl;
		}
	}

	public void setRecodingUrl(String recodingUrl) {
		_recodingUrl = recodingUrl;
	}

	@JSON
	public String getDescription() {
		if (_description == null) {
			return StringPool.BLANK;
		}
		else {
			return _description;
		}
	}

	public void setDescription(String description) {
		_description = description;
	}

	@JSON
	public boolean getIsShow() {
		return _isShow;
	}

	public boolean isIsShow() {
		return _isShow;
	}

	public void setIsShow(boolean isShow) {
		_isShow = isShow;
	}

	@JSON
	public String getAvatar() {
		if (_avatar == null) {
			return StringPool.BLANK;
		}
		else {
			return _avatar;
		}
	}

	public void setAvatar(String avatar) {
		_avatar = avatar;
	}

	@JSON
	public Date getCreateDate() {
		return _createDate;
	}

	public void setCreateDate(Date createDate) {
		_createDate = createDate;
	}

	@JSON
	public long getSongId() {
		return _songId;
	}

	public void setSongId(long songId) {
		_columnBitmask |= SONGID_COLUMN_BITMASK;

		if (!_setOriginalSongId) {
			_setOriginalSongId = true;

			_originalSongId = _songId;
		}

		_songId = songId;
	}

	public long getOriginalSongId() {
		return _originalSongId;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			UserSongs.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public UserSongs toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (UserSongs)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		UserSongsImpl userSongsImpl = new UserSongsImpl();

		userSongsImpl.setUserSongId(getUserSongId());
		userSongsImpl.setUserId(getUserId());
		userSongsImpl.setCommentNumber(getCommentNumber());
		userSongsImpl.setListenNumber(getListenNumber());
		userSongsImpl.setMark(getMark());
		userSongsImpl.setRecodingUrl(getRecodingUrl());
		userSongsImpl.setDescription(getDescription());
		userSongsImpl.setIsShow(getIsShow());
		userSongsImpl.setAvatar(getAvatar());
		userSongsImpl.setCreateDate(getCreateDate());
		userSongsImpl.setSongId(getSongId());

		userSongsImpl.resetOriginalValues();

		return userSongsImpl;
	}

	public int compareTo(UserSongs userSongs) {
		long primaryKey = userSongs.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		UserSongs userSongs = null;

		try {
			userSongs = (UserSongs)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = userSongs.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		UserSongsModelImpl userSongsModelImpl = this;

		userSongsModelImpl._originalUserId = userSongsModelImpl._userId;

		userSongsModelImpl._setOriginalUserId = false;

		userSongsModelImpl._originalSongId = userSongsModelImpl._songId;

		userSongsModelImpl._setOriginalSongId = false;

		userSongsModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<UserSongs> toCacheModel() {
		UserSongsCacheModel userSongsCacheModel = new UserSongsCacheModel();

		userSongsCacheModel.userSongId = getUserSongId();

		userSongsCacheModel.userId = getUserId();

		userSongsCacheModel.commentNumber = getCommentNumber();

		userSongsCacheModel.listenNumber = getListenNumber();

		userSongsCacheModel.mark = getMark();

		userSongsCacheModel.recodingUrl = getRecodingUrl();

		String recodingUrl = userSongsCacheModel.recodingUrl;

		if ((recodingUrl != null) && (recodingUrl.length() == 0)) {
			userSongsCacheModel.recodingUrl = null;
		}

		userSongsCacheModel.description = getDescription();

		String description = userSongsCacheModel.description;

		if ((description != null) && (description.length() == 0)) {
			userSongsCacheModel.description = null;
		}

		userSongsCacheModel.isShow = getIsShow();

		userSongsCacheModel.avatar = getAvatar();

		String avatar = userSongsCacheModel.avatar;

		if ((avatar != null) && (avatar.length() == 0)) {
			userSongsCacheModel.avatar = null;
		}

		Date createDate = getCreateDate();

		if (createDate != null) {
			userSongsCacheModel.createDate = createDate.getTime();
		}
		else {
			userSongsCacheModel.createDate = Long.MIN_VALUE;
		}

		userSongsCacheModel.songId = getSongId();

		return userSongsCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(23);

		sb.append("{userSongId=");
		sb.append(getUserSongId());
		sb.append(", userId=");
		sb.append(getUserId());
		sb.append(", commentNumber=");
		sb.append(getCommentNumber());
		sb.append(", listenNumber=");
		sb.append(getListenNumber());
		sb.append(", mark=");
		sb.append(getMark());
		sb.append(", recodingUrl=");
		sb.append(getRecodingUrl());
		sb.append(", description=");
		sb.append(getDescription());
		sb.append(", isShow=");
		sb.append(getIsShow());
		sb.append(", avatar=");
		sb.append(getAvatar());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", songId=");
		sb.append(getSongId());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(37);

		sb.append("<model><model-name>");
		sb.append("com.mto.module.karaoke.model.UserSongs");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>userSongId</column-name><column-value><![CDATA[");
		sb.append(getUserSongId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userId</column-name><column-value><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>commentNumber</column-name><column-value><![CDATA[");
		sb.append(getCommentNumber());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>listenNumber</column-name><column-value><![CDATA[");
		sb.append(getListenNumber());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>mark</column-name><column-value><![CDATA[");
		sb.append(getMark());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>recodingUrl</column-name><column-value><![CDATA[");
		sb.append(getRecodingUrl());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>description</column-name><column-value><![CDATA[");
		sb.append(getDescription());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>isShow</column-name><column-value><![CDATA[");
		sb.append(getIsShow());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>avatar</column-name><column-value><![CDATA[");
		sb.append(getAvatar());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createDate</column-name><column-value><![CDATA[");
		sb.append(getCreateDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>songId</column-name><column-value><![CDATA[");
		sb.append(getSongId());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = UserSongs.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			UserSongs.class
		};
	private long _userSongId;
	private long _userId;
	private String _userUuid;
	private long _originalUserId;
	private boolean _setOriginalUserId;
	private int _commentNumber;
	private int _listenNumber;
	private int _mark;
	private String _recodingUrl;
	private String _description;
	private boolean _isShow;
	private String _avatar;
	private Date _createDate;
	private long _songId;
	private long _originalSongId;
	private boolean _setOriginalSongId;
	private long _columnBitmask;
	private UserSongs _escapedModelProxy;
}